<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/json.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$("#list input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$("#list input[type='checkbox']").attr("checked", false);
		}
	});
	$(".multi_click").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择供应商");
			return false;
		}
		$("#provider_ids").val(ids);
		$("#dialog").dialog("open");
	});
	$("#export_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择供应商");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#action_form").attr("action", "<?=url('Product::Provider/ExportChecked')?>").submit();
	});
	$("#export_search_btn").click(function(){
		$("#action_form").attr("action", "<?=url('Product::Provider/ExportSearch')?>").submit();
	});
	$(".detail").colorbox({width:"50%", height:"50%", iframe:true});
	$(".edit").colorbox({width:"65%", height:"70%", iframe:true});
	$("#dialog").dialog({autoOpen:false,modal:true});
	var product_categories_data = <?=$product_categories?>;
	$(document).mselect(product_categories_data, 'product_categories_id', 'product_categories_id', "<?=isset($_GET['product_categories_id'])?$_GET['product_categories_id']:0?>");
});
</script>
<fieldset><legend>查询条件</legend>
<form name="search_provider_form" method="get" >
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table" width="80%">
<tr>
	<th>ID</th>
	<td><input type="text" name="id" value="<?=isset($_GET['id']) ? $_GET['id'] : ''?>" /></td>
	<th>名称</th>
	<td><input name="name" type="text" size="50" value="<?=isset($_GET['name']) ? $_GET['name'] : ''?>" /></td>
</tr>
<tr>
	<th>联系人</th>
    <td><input name="contact_person" value="<?=isset($_GET['contact_person']) ? $_GET['contact_person'] : ''?>" type="text" size="20" /></td>
    <th>地址</th>
    <td><input name="address" id="address" value="<?=isset($_GET['address']) ? $_GET['address'] : '';?>" type="text" size="50" /></td>
</tr>
<tr>
	<th>电话</th>
    <td><input name="phone" id="phone" value="<?=isset($_GET['phone']) ? $_GET['phone'] : ''?>" type="text" /></td>
    <th>店铺链接</th>
    <td><input name="link" id="link" value="<?=isset($_GET['link']) ? $_GET['link'] : ''?>" type="text" size="50"/></td>
</tr>
<tr>
	<th>旺旺号</th>
    <td><input name="wang_wang" id="wang_wang" value="<?=isset($_GET['wang_wang']) ? $_GET['wang_wang'] : ''?>" type="text" /></td>
</tr>
<tr>
	<th>供应商类型</th>
    <td>
    	<select name="type">
			<option value="" <?if(isset($_GET['type']) && $_GET['type'] == ''):?>selected="selected"<?endif;?>>请选择...</option>
			<?foreach (Q::ini('custom_flag/product_provider_type') as $pt):?>
			<option value="<?=$pt['value']?>" <? if(isset($_GET['type']) && $_GET['type'] == $pt['value']):?>selected="selected"<? endif;?>><?=$pt['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>

<tr>
	<th>跟进人员</th>
    <td>
    	<select name="follow_user_id" id="follow_user_id" dataType="Require"  msg="请选择采购人员">
		  <option value="0">请选择...</option>
		  <? foreach($user as $u):?>
		  <option value="<?=$u['id'];?>" <? if(isset($_GET['follow_user_id']) and ($_GET['follow_user_id']==$u['id'])):?>selected="selected"<? endif;?>><?=$u['name'];?></option>
		  <? endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>选择分类</th>
	<td colspan="3"><input type="hidden" id="product_categories_id" name="product_categories_id" /></td>
</tr>
<tr>
	<th>跟进状态</th>
	<td>
		<label><input type="checkbox" name="status[1]" value="1" <?if (isset($_GET['status']) && in_array(1, $_GET['status']))echo 'checked="checked"'?> /> 跟进中</label> 
		<label><input type="checkbox" name="status[0]" value="0" <?if (isset($_GET['status']) && in_array(0, $_GET['status']))echo 'checked="checked"'?> /> 跟进人已离职</label>
		<label><input type="checkbox" name="status['']" value="" <?if (isset($_GET['status']) && in_array('', $_GET['status']))echo 'checked="checked"'?> /> 没人跟进</label>
	</td>
</tr>
<tr>
	<th/></th>
	<td><input type="submit" class="button" value="查找" /></td>
</tr>
</table>
</form>
</fieldset>
<table width="100%" class="list_table" id="list">
	<tr>
		<th width="30"></th>
		<th>ID</th>
		<th>名称</th>
		<th>已绑分类</th>
		<th>供应商类型</th>
		<th>联系人</th>
		<th>电话</th>
		<th>跟进人员</th>
		<th>操作</th>
	</tr>
	<? foreach($provider as $p):?>
	<tr <?if(!$p['user_status'])echo 'bgcolor="#FF9912"';?>>
		<td><input type="checkbox" value="<?=$p['id']?>" /></td>
		<td><?=$p['id'];?></td>
		<td><a class="detail" href="<?=url('Product::Provider/Detail', array('id'=>$p['id']));?>"><?=$p['name'];?></a></td>
		<td align="left">
			<?foreach ($p['categories'] as $c):?>
			[<?=$c['name']?>]
			<?endforeach;?>
		</td>
		<td title="<?if ($p['type'] == Q::ini('custom_flag/product_provider_type/online/value')):?>
旺旺号：<?=isset($p['wang_wang']) ? $p['wang_wang'] : ''?>	
店铺链接：<?=isset($p['link']) ? $p['link'] : ''?>
			<?endif;?>"><?=Helper_BSS_Normal::getIniOne('product_provider_type', 'value', $p['type'], 'name')?>
		</td>
		<td><?=$p['contact_person'];?></td>
		<td><?=empty($p['phone']) ? $p['cellphone'] : $p['phone'];?></td>
		<td><?=$p['follow_user_name'];?></td>
		<td><a href="<?=url('Product::Provider/Edit', array('id'=>$p['id']));?>" class="edit">编辑</a></td>
	</tr>
	<? endforeach;?>
</table>
<?=$page;?>
<table class="list_table">
<tr>
	<td rowspan="5"><label><input type="checkbox" id="check_all" /> 全选</label></td>
	<td><label><input type="button" class="button multi_click" value="批量跟进" /></label></td>
</tr>
<tr>
	<td align="left">导出：
		<input type="button" class="button" id="export_btn" value="按勾选" />
		<input type="button" class="button" id="export_search_btn" value="按条件" />
	</td>
</tr>
</table>
<div id="dialog" title="批量添加跟进人员">
<form method="post" action="<?=url('Product::Provider/MultipleAddFollowUser')?>">
<input type="hidden" name="provider_ids" id="provider_ids" value="" />
<select name="follow_user_id">
	<option value="">请选择..</option>
	<?foreach ($user as $u):?>
	<option value="<?=$u['id']?>"><?=$u['name']?></option>
	<?endforeach;?>
</select>
<input type="submit" value="添加" class="button" />
</form>
</div>
<form id="action_form" action="" method="post" target="">
	<input type="hidden" name="url_arr" value='<?=$url_arr?>' />
	<input type="hidden" id="ids" name="ids" value="" />
	<input type="hidden" name="form_move_cat_id" id="form_move_cat_id" value="" />
</form>
<?php $this->_endblock();?>